<?php

namespace App\Console\Commands;

use App\Models\Meeting;
use App\Models\UserInfos;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Cache;

class Sms extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'command:sms';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        // 现在的时间戳
        $time = time();
        // 数据库读取数据
        $data = Meeting::all()->toArray();
        foreach ($data as $val){
            // 数据库的时间戳加上十五分钟跟  现在的时间比较
            if ($val['begin_time']-$time==1800){
                // 获取会议发起人的手机号
                $phone = UserInfos::where('id',$val['user_id'])->first()->toArray()['phone'];
                // 发送短信
                \App\Services\Sms::send($phone,'您的会议还有15分钟开始');
            }
        }
    }
}
